package com.weilian.androidgames.chicken;

import com.weilian.androidgames.framework.Game;
import com.weilian.androidgames.framework.Graphics;
import com.weilian.androidgames.framework.Input.TouchEvent;
import com.weilian.androidgames.framework.Screen;
import java.util.List;

public class MainMenuScreen extends Screen {

	boolean clicked;
	public MainMenuScreen(Game game) {
		super(game);
		clicked = false;
	}

	@Override
	public void update(float deltaTime) {
		Graphics g = game.getGraphics();
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();
		
		int len = touchEvents.size();
		
		for(int i = 0; i < len;i++) {
			TouchEvent event = touchEvents.get(i);
			if(event.type == TouchEvent.TOUCH_UP) {
				if(inBounds(event, 64, 100, 227, 41)){
					clicked = false;
					game.setScreen(new PlayScreen(game));
				}
			}
			if(event.type == TouchEvent.TOUCH_DOWN) {
				if(inBounds(event, 64, 100, 227, 41)) {
					clicked = true;
				}
			}
		}
		
	}
	
	private boolean inBounds(TouchEvent event, int x , int y, int width, int height) {
		if(event.x > x && event.x < x + width - 1 &&
		   event.y > y && event.y < y + height - 1)
			return true;
		else return false;
	}

	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		drawMenuButtons(g);
	}
	
	private void drawMenuButtons(Graphics g) {
		g.drawPixmap(Assets.background, 0, 0);
		if(clicked)
			g.drawPixmap(Assets.playClicked, 64, 100);
		else
			g.drawPixmap(Assets.playUnclicked, 64, 100);
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

}
